define(['knockout', 'jquery', 'text!./ref-win.btl'], function (ko, $, template) {
    function ReferenceWindow(params, componentInfo) {
    	var self = this;
    	self.element = $(componentInfo.element);
    	self.service = ko.rest.service('/rest/productline');
    	
    	self.divId = params.id;
    	self.entities = ko.observableArray([]);

    	self.initContent = function() {
    		self.init($(this.element));
    	}
    }
    
    ReferenceWindow.prototype.init = function(element) {
    	var self = this;
    	element.jqxWindow({ okButton: element.find('#btn_OK')});
    	element.jqxWindow({ cancelButton: element.find('#btn_Cancel')});
//        $(this.element).find('#ref-grid').jqxGrid('localizestrings', getLocalization('zh-CN'));
         
    	element.on('open', function (event) { 
    		self.refresh();
        }); 
        
        element.on('close', function (event) { 
             
        });
    }

    
    ReferenceWindow.prototype.refresh = function() {
    	var self = this;
    	self.service.query(function(data) {
    		self.entities(flat(data));
        });
    }

    // This runs when the component is torn down. Put here any logic necessary to clean up,
    // for example cancelling setTimeouts or disposing Knockout subscriptions/computeds.
    ReferenceWindow.prototype.dispose = function () { };
   
    return {
        viewModel: {
            createViewModel: function (params, componentInfo) {
                var initialData = [
                    { name: "Well-Travelled Kitten", code: "xxxx", taktTime: "32", taktUnit: "小时" }
                ];

                return new ReferenceWindow({id: params.id}, componentInfo);
            }
        },
        template: template
    };
});
